package com.som.service.excel.data3.state;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.som.bean.data3.IpAddressInfo;
import com.som.bean.data3.IpMaskInfo;
import com.som.bean.data3.IpSectionInfo;
import com.som.console.CfgEnum;

/**
 * 进行状态切换的上下对象
 * 
 * @author liujun
 * @date 2016年4月12日
 * @verion 0.0.1
 */
public class StateContext
{
	/**
	 * 进行数据转换的map
	 */
	@SuppressWarnings({ "rawtypes" })
	private Map<String, ParseStateInf> parseMap = new HashMap<String, ParseStateInf>();

	/**
	 * 将数据转换到IP的对象信息
	 */
	private ParseStateInf<List<IpAddressInfo>> parseIp = new ParseIpStateImp(this);

	/**
	 * 转换为IP段的形式
	 */
	private ParseStateInf<List<IpSectionInfo>> parseIpsection = new ParseIpSectionStateImp();

	/**
	 * 将数据转换为IP掩码形式
	 */
	private ParseStateInf<List<IpMaskInfo>> parseIpMask = new ParseIpMaskStateImp(this);

	/**
	 * 当前进行转换的类
	 */
	@SuppressWarnings({ "rawtypes" })
	private ParseStateInf currParse;

	public StateContext()
	{
		this.parseMap.put(CfgEnum.SYSTEM_FORMAT_TYPE_IP.getCfgMsg(), parseIp);
		this.parseMap.put(CfgEnum.SYSTEM_FORMAT_TYPE_IPSECTION.getCfgMsg(), parseIpsection);
		this.parseMap.put(CfgEnum.SYSTEM_FORMAT_TYPE_IPMASK.getCfgMsg(), parseIpMask);
	}

	public ParseStateInf<List<IpAddressInfo>> getParseIp()
	{
		return parseIp;
	}

	public ParseStateInf<List<IpSectionInfo>> getParseIpsection()
	{
		return parseIpsection;
	}

	public ParseStateInf<List<IpMaskInfo>> getParseIpMask()
	{
		return parseIpMask;
	}

	@SuppressWarnings("rawtypes")
	public ParseStateInf getCurrParse(String key)
	{
		return parseMap.get(key);
	}

	public void setCurrParse(String key)
	{
		this.currParse = parseMap.get(key);
	}

	@SuppressWarnings("rawtypes")
	public ParseStateInf getCurrParse()
	{
		return currParse;
	}

	/**
	 * 将当前的参数的转换为ip形式
	 * 
	 * @param param
	 *            参数信息
	 * @return IP信息
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<IpAddressInfo> parseIp(String key, List input)
	{
		ParseStateInf parseINf = this.getCurrParse(key);
		return parseINf.parseIp(input);
	}

	/**
	 * 将当前的参数转换为IP段形式
	 * 
	 * @param param
	 *            参数信息
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<IpSectionInfo> parseIpSection(String key, List input)
	{
		ParseStateInf parseINf = this.getCurrParse(key);
		return parseINf.parseIpSection(input);
	}

	/**
	 * 将当前的参数转换为IP掩码形式
	 * 
	 * @param param
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List<IpMaskInfo> parseIpMask(String key, List input)
	{
		ParseStateInf parseINf = this.getCurrParse(key);
		return parseINf.parseIpMask(input);
	}

}
